<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace app\admin\controller;

use app\admin\model\Conf as ConfModel;
class Conf extends Common{
    //TODO 配置暂时不用
    public function conf(){
        $conf=new ConfModel();
        $res=$conf->getConf();
        if(request()->isPost()){
            $data=input('post.');
            foreach ($data as $k=>$v){
                $conf->where("enname",$k)->update(['value' => $v]);
            }
            $this->success("修改成功",'conf');
        }
        $this->assign("res",$res);
        return  view();
    }
    public function lst(){
        $conf=new ConfModel();
        $res=$conf->getConf();
        $this->assign("res",$res);
        return view();
    }
    public function add(){
        if(request()->isPost()){
            $data=input('post.');
            $data["values"]=str_replace("，",",",$data["values"]);
            $conf=new ConfModel();
            if($conf->save($data)){
                return $this->success("添加成功","lst");
            } else {
                return $this->error("添加失败","lst");
            }
        }
        return view();
    }
    public function edit($id){
        $conf=new ConfModel();
        $res=$conf->getTconf($id);
        $this->assign("res",$res);
        if(request()->isPost()){
            $data=input('post.');
            $data["values"]=str_replace("，",",",$data["values"]);
            $conf=new ConfModel();
            if($conf->update($data)){
                return $this->success("更新成功","lst");
            } else {
                return $this->error("更新失败","lst");
            }
        }
        return view();
    }
    public function del(){
        $id=input('id');
        $conf=new ConfModel();
        if($conf->destroy($id)){
           return $this->success('删除成功','lst'); 
        }else{
            return $this->error('删除失败','lst');
        } 
    }
}
